<?php
    include_once '../../../../controlador/php/conexion/Conexion.php';
    $con = new Conexion();
    
    $fecha1 = $_REQUEST['capass2'];
    $fecha2 = $_REQUEST['capass22'];
    
    $f1 = date('Y-m-d',strtotime($fecha1));
    $f2 = date('Y-m-d',strtotime($fecha2));
    
    $indi = "select case when ate_formTerEmb = 'cs' then 'Pacientes que se les aplico cesarea' end as ate, atem.total
            from atenMaterna as atm
            outer apply(select COUNT(DISTINCT adnIngreso) as total 
                                    from atenMaterna 
                                    where ate_fecha between '".$f1."' and '".$f2."'and ate_formTerEmb = 'cs')as atem
            where ate_formTerEmb ='cs' 
            group by ate_formTerEmb,atem.total
            union
            select case when ate_formTerEmb = 'pi' then 'Pacientes con parto instrumentado' end as ate, atem.total
            from atenMaterna as atm
            outer apply(select COUNT(DISTINCT adnIngreso) as total 
                                    from atenMaterna 
                                    where ate_fecha between '".$f1."' and '".$f2."'and ate_formTerEmb = 'pi')as atem
            where ate_formTerEmb ='pi' 
            group by ate_formTerEmb,atem.total
            union
            select case when ate_formTerEmb = 'pe' then 'Pacientes con parto espontaneo' end as ate, atem.total
            from atenMaterna as atm
            outer apply(select COUNT(DISTINCT adnIngreso) as total 
                                    from atenMaterna 
                                    where ate_fecha between '".$f1."' and '".$f2."'and ate_formTerEmb = 'pe')as atem
            where ate_formTerEmb ='pe' 
            group by ate_formTerEmb,atem.total";
    $lsti = $con->query($indi);
    while($res = mssql_fetch_array($lsti)){
        $lst[] = $res;
    }
    $con->cerrarConexion();
    print_r(json_encode($lst));

?>
